import redis

# 连接Redis
conn = redis.Redis(host="192.168.5.132")


# 1、添加数据
# 左推
# res = conn.lpush("fans", "zhangsan")   # 返回的是元素个数
# print(res)
# res = conn.lpush("fans", "lisi")
# print(res)

# 右推
# res = conn.rpush("fans", "bill gates")
# print(res)
# res = conn.rpush("fans", "王麻子")
# print(res)




# 2、查看元素
# fans = conn.lrange("fans", 0, -1)
# print(fans)

# 切片
# fans = conn.lrange("fans", 0, 1)  # 两头都会取到
# print(fans)


# 根据索引获取元素
# first = conn.lindex("fans", 0)  # 获取第一个元素
# print(first)

# 3、修改元素

# res = conn.lset("fans", 2, "weige")
# fans = conn.lrange("fans", 0, -1)
# print(fans)

# 4、删除元素
# res = conn.lrem("fans", 1, "zhangsan")  # 根据 value
# fans = conn.lrange("fans", 0, -1)
# print(fans)

# 根据指定位置
# conn.lpush("fans", "zhangsan")
#
# fans = conn.lrange("fans", 0, -1)
# print(fans)

# res = conn.rpop("fans")  # 删除最右边的元素
# print(res)
# fans = conn.lrange("fans", 0, -1)
# print(fans)